var listionhajax = '';
var is_ajax_list = '';
var page = 2;

function update_user() {

	var bankno = $('.bankno').val();
	var province = $('.province').val();
	var city = $('.city').val();
	var address = $('.address').val();
	var accntnm = $('.accntnm').val();
	var accntno = $('.accntno').val();
	var scard = $('.scard').val();
	var phone = $('.phone').val();
	var id = $('.id').val();
	var uid = $('.uid').val();


	if(!bankno){layer.msg('请选择银行');return false;}
	if(!province){layer.msg('请选择省份');return false;}
	if(!city){layer.msg('请选择城市');return false;}
	if(!address){layer.msg('请输入支行地址');return false;}
	if(!accntnm){layer.msg('请输入开户名称');return false;}
	if(!accntno){layer.msg('请输入卡号');return false;}
	if(!scard){layer.msg('请输入身份证号码');return false;}
	if(!phone){layer.msg('请输入手机号');return false;}


	var postdata = 'bankno='+bankno+"&provinceid="+province+"&cityno="+city+"&address="+address+"&accntnm="+accntnm+"&accntno="+accntno+"&scard="+scard+"&phone="+phone;
	if(id){
		postdata += "&id="+id
	}
	if(uid){
		postdata += "&uid="+uid
	}
	var posturl = "/index/user/dobanks";
	$.post(posturl,postdata,function(resdata){
		layer.msg(resdata.data);

		if(resdata.type == 1){
			setTimeout('gourl()',1000);
		}

	})


}




function gourl() {

	history.go(0);
}


/**
 * 出金申请
 * @author lukui  2017-07-04
 * @return {[type]} [description]
 */
function out_withdraw() {

	var price = $('.cash-price').val();
	var cash_min = $('.cash_min').html();
	var cash_max = $('.cash_min').attr('attrmax');
	if(price*10 < cash_min*10){
		layer.msg('最低提现金额为'+cash_min);
		return false;
	}

	if(price*10 > cash_max*10){
		layer.msg('最高提现金额为'+cash_max);
		return false;
	}

	var postdata = 'price='+price;
	var posturl = '/index/user/cash';
	$.post(posturl,postdata,function(resdata){

		layer.msg(resdata.data);
		if(resdata.type == 1){
			setTimeout('gourl()',1000);
		}

	})






}

	/**
	 * 监听输入提现金额
	 * @author lukui  2017-07-05
	 * @param  {[type]} ) {		var       price [description]
	 * @return {[type]}   [description]
	 */
	$('.cash input').bind('input propertychange', function() {
		var price = $('.cash-price').val();
		var reg_par = $('.reg_par').attr('attrdata');
		var true_price = (price*(100-reg_par)/100).toFixed(2);
		$('.true_price').html(true_price);
		$('.true_price').show();

	});

/**
 * 资金流水
 * @author lukui  2017-07-05
 * @param  {[type]} ){	var isshow        [description]
 * @return {[type]}         [description]
 */
$(document).on("click",'.price_list li',function(){

	var isshow = $(this).attr('isshow');
	if(isshow == 0){

		$('.today_list_footer').hide();
		$('.price_list li').attr('isshow',0);
		$('.clickshow').addClass('ion-ios-arrow-up');
		$('.clickshow').removeClass('ion-ios-arrow-down');


		$(this).find('.clickshow').removeClass('ion-ios-arrow-up');
		$(this).find('.clickshow').addClass('ion-ios-arrow-down');

		$(this).find('.today_list_footer').show();
		$(this).attr('isshow',1);

	}else{

		$(this).find('.clickshow').addClass('ion-ios-arrow-up');
		$(this).find('.clickshow').removeClass('ion-ios-arrow-down');

		$(this).find('.today_list_footer').hide();
		$(this).attr('isshow',0);

	}


});



listionhajax = setInterval("listionh()",1000);
/**
 * 监听高度
 * @author lukui  2017-07-05
 * @return {[type]} [description]
 */
function listionh() {
    if($(".price_list li:last").attr('ng-repeat')){
        var ScrollTop = $(".price_list li:last").offset().top;

        if(ScrollTop <1000 ){
        	ajax_price_list();
        }
    }

}

/**
 * ajax加载资金流水
 * @author lukui  2017-07-05
 * @return {[type]} [description]
 */
function ajax_price_list() {


	var url = "/index/user/ajax_price_list?page="+page;
    var html = '';
    if(is_ajax_list == 1){
        return ;
    }
    is_ajax_list = 1;


    $.get(url,function(resdata){

        console.log(resdata);


        var res_list = resdata.data;
        if(res_list.length == 0){
            clearInterval(listionhajax);
            is_ajax_list = 1;
            return;
        }
        $.each(res_list,function(k,v){
        	if(v.type == 2){
        		var other_money = v.account*-1;
        	}else{
        		var other_money = v.account;
        	}
        	html += '<li ng-repeat="c in moneyList" class="" isshow="0">\
                	<div class="money_list_header">\
                		<section class="other_money_bg">\
                		</section><section>\
                			<p class="ng-binding other_money">'+v.title+'</p>\
                			<p>\
                				<i class="iconfont icon--1 "></i>\
                				<i class="iconfont icon-30 ng-hide"></i>\
                				<span class="ng-binding">'+v.nowmoney+'</span></p>\
                			<p>\
                				<i class="iconfont icon--2 pay_blue"></i>\
                				<span class="ng-binding">'+getLocalTime(v.time)+'</span>\
                			</p>\
                		</section><section class="ng-binding other_money">\
                			'+other_money+'                		</section><section class="icon clickshow ion-ios-arrow-up">\
                		</section>\
                	</div>\
                	<article class="today_list_footer" style="display: none;">\
                		<p class="ng-binding">详情：'+v.content+'</p>\
                	</article>\
                </li>';



    	})
        $('.price_list').append(html);
        page++;
        is_ajax_list = 0;

    })




}


/**
 * 发送验证码
 * @return {[type]} [description]
 */
function get_svg() {
	var phone = $('.username').val();
	if(!(/^1[34578]\d{9}$/.test(phone))){
        layer.msg("请正确输入手机号！");
        return false;
    }


	var url = "/index/api/sendmsm/phone/"+phone;
	$.get(url,function(resdata){
		console.log(resdata);
		layer.msg(resdata.data);
		if(resdata.type == 1){
			$(".code_btn").attr('onclick',"return false;");
			listion_sendmsm();
		}
	})
	return false;
}

function listion_sendmsm(){

	 var time= 61;
    setTime=setInterval(function(){
        if(time<=1){
            clearInterval(setTime);
            $(".code_btn").text("再发一次");
            $(".code_btn").attr('onclick',"return get_svg();");
            return;
        }
        time--;
        $(".code_btn").text(time+"s");

    },1000);
}
/**
 * 充值
 * @return {[type]} [description]
 * 2019.7.30
 */
function submit_deposit_new() {
	
	can_balance(0)
	
	var bpprice = $('.bpprice').val();
	if(!bpprice || isNaN(bpprice)){
		layer.msg('请输入充值金额');
		can_balance(1)
		return false;
	}

	var posturl = "/index/user/addbalance_untra";
		pay_type='untrapay'
		var postdata = "pay_type="+pay_type+"&bpprice="+bpprice;
	

	$.post(posturl,postdata,function(res){
		
		$('#zypay_post').html(res);
		$("#zypay_post form").submit();

	})
}

/**
 * 充值
 * @return {[type]} [description]

 */
function submit_deposit() {

	can_balance(0)
	if(pay_type == ''){
		layer.msg('请选择支付类型');
		can_balance(1)
		return false;
	}

	var bpprice = $('.bpprice').val();
	if(!bpprice || isNaN(bpprice)){
		layer.msg('请输入充值金额');
		can_balance(1)
		return false;
	}
    if(pay_type=='ppy_pay')
     {
        var bpprice = $('.bpprice').val();
  
  		if( bpprice=='227'|| bpprice=='670' )
  		{
          	pay_type == 'hot_wechat';
          	location.href = res;
  
  	    } 
       if( bpprice=='1000'|| bpprice=='2000'|| bpprice=='5000'|| bpprice=='10000'|| bpprice=='500')
  		{
          	pay_type == 'starfireotc_pay';
          	location.href = res;
  	    } 
      	if( bpprice=='20000'|| bpprice=='49999'|| bpprice!='500')
  		{
          	pay_type == 'bank_pay';
			location.href = "/bank/bank.html";	
  	    } 
       
            
      }
  
  
  
  
  
  if(pay_type == 'starfireotc_pay')
   { 
         var bpprice = $('.bpprice').val();

          
     
       	if(bpprice=='20000'|| bpprice=='49999')
     {
     	 alert("请选择网银支付");
           // location.replace(location.href);
       can_balance(1)
		return false;
     }
       	if(bpprice=='200'||bpprice=='500')
     {
     	 alert("请选择支付宝支付");
           // location.replace(location.href);
       can_balance(1)
		return false;
     }

   }
    if(pay_type == 'bank_pay')
   { 
         var bpprice = $('.bpprice').val();

         
     
       	if(bpprice=='1000'|| bpprice=='2000')
     {
     	 alert("请选择聚合支付");
            //location.replace(location.href);
       can_balance(1)
		return false;
     }
          	if( bpprice=='200'||bpprice=='500')
     {
     	 alert("请选择支付宝支付");
            //location.replace(location.href);
       can_balance(1)
		return false;
     }

   }
  if(pay_type == 'ceshi')
   { 
         var bpprice = $('.bpprice').val();

          
     
       	if(bpprice=='10000'||bpprice=='20000'|| bpprice=='49999')
     {
     	 alert("请选择网银转账");
            //location.replace(location.href);
       can_balance(1)
		return false;
     }

   }
  
  
   if(pay_type == 'hot_wechat')
   {
        var bpprice = $('.bpprice').val();
      if(bpprice=='5000'|| bpprice=='10000'|| bpprice=='1000'|| bpprice=='2000')
              {
                 alert("请选择聚合支付");
               // location.replace(location.href);
                can_balance(1)
				return false;
                
            
              }
     
     
     }
   if(pay_type == 'hot_alipay')
   {
        var bpprice = $('.bpprice').val();
      if(bpprice=='5000'|| bpprice=='10000'|| bpprice=='1000'|| bpprice=='2000')
              {
                 alert("请选择聚合支付");
               // location.replace(location.href);
                can_balance(1)
				return false;
            
              }
     
     }
  
  	if(pay_type == 'pdd_wechat')
    { 
     
            var bpprice = $('.bpprice').val();
           if(bpprice=='5000'|| bpprice=='10000'|| bpprice=='1000'|| bpprice=='2000')
              {
                 alert("请选择聚合支付");
                location.replace(location.href);
            
              }
    }
  		if(pay_type == 'pdd_alipay')
   		 { 
     
            var bpprice = $('.bpprice').val();
           if(bpprice=='5000'|| bpprice=='10000'|| bpprice=='1000'|| bpprice=='2000')
              {
                 alert("请选择聚合支付");
                location.replace(location.href);
            
              }
    }
 
	
  //20181026 云支付 start
	var posturl_yun = "/index/user/addbalance_yun";
	var postdata_yun = "pay_type="+pay_type+"&bpprice="+bpprice;
 	if(pay_type=='yunzhifu_wx'||pay_type=='yunzhifu_ali'|| pay_type == 'yunzhifu_ysf'){

		//询问框
        layer.confirm('是否确定支付 '+$('.bpprice').val()+' ?', {
          cancel: function(index, layero){
  			//location.reload();
  			can_balance(1);
          },
          btn: ['确定','取消'] //按钮
        }, function(){
          //layer.msg('的确很重要', {icon: 1});
          // console.log(res);
  		//location.href = "/index/user/addbalance_yun?"+postdata;


          $.post(posturl_yun,postdata_yun,function(res){
            if(res.type == -1){
                layer.msg(res.data,{
                  //offset: 'b',
  				time: 8000 //5秒关闭（如果不配置，默认是3秒）
  			  }, function(){
  				//do something
                  can_balance(1);
  			});

                //can_balance(1);

            }else{

              //location.href = res;
              location.href = "/index/user/addbalance_yun"
            }
          });

  		return;
        }, function(){
          //location.reload();
          can_balance(1);
  		return;
        });

  		return;

	}
  //20181026 云支付 end


	var posturl = "/index/user/addbalance";

	if(pay_type == "keguan"){
		var keguantype = $('#keguantype').val();
		if(keguantype == 0){
			layer.msg('请选择支付方式');
			can_balance(1)
			return false;
		}
		var postdata = "pay_type="+pay_type+"&bpprice="+bpprice+"&keguantype="+keguantype;
	}else{
		var postdata = "pay_type="+pay_type+"&pay_code="+pay_code+"&bpprice="+bpprice;
	}
  

	
	$.post(posturl,postdata,function(res){

		if(res.type == -1){
          
          alert("正在请求下单，请稍等");
          submit_deposit();
          
		}else{
			if(pay_type == 'wxpay'){
				wxpay_info = JSON.parse(res);
				callpay(wxpay_info);
			}
			if(pay_type == 'zypay'){
				$('#zypay_post').html(res);

			}
			if(pay_type == 'zypay_wx'){
				var qrcode = res;
	 			$('.pay_code_img').html('<img src="'+res+'" style="width: 100%;">');
	 			pay_code_area(1);
	 			can_balance(1);

			}
          	if(pay_type=='yilian_ali'||pay_type=='yilian_bank'){
              	$('#zypay_post').html(res);
				$("#zypay_post form").submit();
			}
            if(pay_type=='shengbao_ali'||pay_type=='shengbao_wx'){
              	$('#zypay_post').html(res);
				$("#zypay_post form").submit();
			}
            if(pay_type=='ruibao_kj'){
              	$('#zypay_post').html(res);
				$("#zypay_post form").submit();
			}
            if(pay_type=='qddpay_kj'){
              	location.href = res;
			}
			//-------
			if(pay_type=='qinguochang_ali_h5'||pay_type=='qinguochang_wx'||pay_type=='qinguochang_uni_scan'){
              	console.log(res);
				location.href = '/index/user/show_qr?d='+res;
			}
			if(pay_type=='qinguochang_ali_h55'){
              	console.log(res);
				var t=JSON.parse(res);
				location.href =t.data.code_url ;
			}
			if(pay_type=='qinguochang_uni_wap'){
              	console.log(res);
				$('#zypay_post').html(res);
				$("#zypay_post form").submit();
			}
			//----------

          if(pay_type=='yingshen_wx'||pay_type=='yingshen_ali'){
				$('#zypay_post').html(res);
				$("#zypay_post form").submit();
			}
          if(pay_type=='bncp_kuaijie'||pay_type=='bncp_ali'){
				$('#zypay_post').html(res);
				$("#zypay_post form").submit();
			}
			//20190303 hzitong start
			if(pay_type=='hzitong_wx'||pay_type=='hzitong_ali'||pay_type=='hzitong_bank'||pay_type=='hzitong_kuaijie'||pay_type=='hzitong_icbc'||pay_type=='hzitong_ccb'||pay_type=='hzitong_abc'){
				$('#zypay_post').html(res);
				$("#zypay_post form").submit();
			}
			//20190303 hzitong end
			if(pay_type=='cnt_pay_shouyingtai'||pay_type=='cnt_pay_ali'||pay_type=='cnt_pay_wx'){

				var t={};
				t=JSON.parse(res);
				if(t.resultCode!='0000'){
					layer.msg(t.resultMsg);
					can_balance(1);
					console.log(t);

				}else{
					// location.href = res;
					location.href = t.data.payPage;
				}


			}

			//20180208 智能云支付 start
			if(pay_type=='znyzhifu_wx'||pay_type=='znyzhifu_ali'){
				location.href = res;
			}
			//20180208 智能云支付 end

			//20181015 类智能云支付 pay10086 start
			if(pay_type=='pay10086_wx'||pay_type=='pay10086_ali'){
				// location.href = res;
				$('#zypay_post').html(res);
				$("#zypay_post form").submit();
			}
			//20181015 类智能云支付 pay10086 end

			if( pay_type == 'zypay_yl'){
				$('#zypay_post').html(res);

	 			can_balance(1);

			}

			if(pay_type == 'qtb_pay_wxpay_code' || pay_type == 'qtb_alipay'){
				//location.href = res;
				var qrcode = res.data;
	 			sQrcode(qrcode,'pay_code_img');
	 			pay_code_area(1);
	 			can_balance(1);

			}
			if(pay_type == 'qtb_wx_wap'){
				location.href = res;
			}
			if(pay_type == 'alipay'){
				$('#zypay_post').html(res);
			}
			// if(pay_type == 'qtb_alipay'){
			// 	location.href = res;
			// }
			if(pay_type == 'qtb_yinlian'){
				location.href = res;
			}
			if(pay_type == 'qtb_wxpay'||pay_type == 'mcb_wxpay'||pay_type == 'mcb_alipay'){
				location.href = res;
			}
			if(pay_type == 'izpay_wx' || pay_type == 'izpay_alipay' ){

				var objs = JSON.parse(res);
				console.log(objs);
				if(objs.status == 0){
					location.href = objs.code_url;
				}else{
					layer.msg('请稍后重试')
				}
				//
			}
			if(pay_type == 'WeixinBERL' || pay_type == 'Weixin' || pay_type == 'AlipayCS' || pay_type == 'AlipayPAZH'){

				if(res.errcode == 0){
					var jsapi_pay_url = res.data.jsapi_pay_url;

					var qrcode = jsapi_pay_url;
		 			sQrcode(qrcode,'pay_code_img');
		 			pay_code_area(1);
		 			can_balance(1);

					//location.href = jsapi_pay_url;
				}
				console.log(res);

			}

			if(pay_type == 'qt_wx_code'){

				if(res.type == -1){
					layer.msg(res.data);
					pay_code_area(1);
		 			can_balance(1);
					return false;
				}else{
					var jsapi_pay_url = res;
					var qrcode = jsapi_pay_url;
		 			sQrcode(qrcode,'pay_code_img');
		 			pay_code_area(1);
		 			can_balance(1);
				}


			}

			if(pay_type == 'qt_kuaijie'){

				if(res.type == -1){
					layer.msg(res.data);
					pay_code_area(1);
		 			can_balance(1);
					return false;
				}else{
					$('#zypay_post').html(res);
					$("#zypay_post form").submit();

		 			can_balance(1);
				}


			}

			if(pay_type == 'wx_wap_2'){

				if(res.type == -1){
					layer.msg(res.data);
					pay_code_area(1);
		 			can_balance(1);
					return false;
				}else{
					location.href = res;
		 			can_balance(1);
				}


			}

			if(pay_type == 'wxPub'){
				location.href = res;
	 			can_balance(1);
			}

			if(pay_type == 'wxPubQR'){

				var objs = JSON.parse(res);

				var qrcode = objs.codeUrl;
	 			sQrcode(qrcode,'pay_code_img');
	 			pay_code_area(1);
				can_balance(1);
			}

			if(pay_type == 'mcpay'){

				var gourl = '/index/user/mcpay.html?id='+res.bpid;
				location.href = gourl;
	 			can_balance(1);
			}

			if (pay_type == 'yika_KUAIJIE' || pay_type == 'yika_WEIXIN') {
				$('#zypay_post').html(res);
				$("#zypay_post form").submit();
			}
			if (pay_type == 'keguan' || pay_type == 'ysy_wxwap'  ) {
				location.href = res;
			}

			// if (pay_type == "ysy_alwap" || pay_type == 'ysy_wxcode') {
				// $('.pay_code_img').html('<img src="http://pan.baidu.com/share/qrcode?w=700&h=700&url='+res+'" width="100%">');
				// $('.pay_code_area').show();
			// }
			if(pay_type == 'zx_wxzf'){
				window.location = '/index/user/zxwxzf?money='+bpprice;
			}
			if (pay_type == 'ysy_alwap') {
				window.location = '/index/user/zxzfbzf?money='+bpprice;
			}
			if(pay_type == 'zypay_qq'){
				window.location = '/index/user/zxqqsmzf?money='+bpprice;
				// $.ajax({
					// url:"/index/user/zxqqsmzf",
					// data: "money="+bpprice,
					// // dataType: "json",
					// type: "post",
					// success: function(data){
						// alert(data)
					// }
				// });

			}

			// 20171229 聪付
			if(pay_type == 'congfupay_wx_wap'||pay_type == 'congfupay_qq_wap'){
				// alert(res);
				console.log(res);
				if(res.indexOf('http')!=0){
					layer.msg('今日流水达到上限！'+res);
					// can_balance(1);
				}else{
					location.href = res;
				}
				// $('#zypay_post').html(res);
				// $("#zypay_post form").submit();

			}
			if(pay_type=='shpay_dg'||pay_type=='shpay_wx'||pay_type=='shpay_alipay'||pay_type=='shpay_bank'){
				
				location.href = res;
			}
			if(pay_type=='ymepay_zfbwap' || pay_type=='ymepay_zfbsm'){
				
				location.href = res;
			}
				if(pay_type == 'starfireotc_pay'){
				location.href = res;
			}
			if(pay_type == 'huihe_pay' ) {
				location.href = res;
			}
			if(pay_type == 'juhe_pay') {
				location.href = res;
			}
          if(pay_type == 'wechatt_pay'){
				location.href = "/wechat_pay/wechat.html";
			}
          if(pay_type == 'alipay_payy'){
				location.href = "/alipay_pay/alipay.html";
			}
          if(pay_type == 'bank_pay'){
			location.href = "/bank/bank.html";	
          }
          if(pay_type == 'pdd_wechat'){
           
				location.href = res;
			}
          if(pay_type == 'pdd_alipay'){

				location.href = res;
			}
          if(pay_type == 'hot_wechat'){
           
				location.href = res;
			}
          if(pay_type == 'hot_alipay'){

				location.href = res;
			}
          if(pay_type == 'ceshi'){

				location.href = res;
			}
           if(pay_type == 'saoma_alipay'){

				location.href = res;
			}
           if(pay_type == 'saoma_wechat'){

				location.href = res;
			}
		}


	})
}

function check_payid(id, code) {
	pay_type = id;
	pay_code = code;
}


//调用微信JS api 支付
function jsApiCall(obj)
{

    WeixinJSBridge.invoke(
        'getBrandWCPayRequest',
        obj,
        function(res){
            WeixinJSBridge.log(res.err_msg);
            //alert(res.err_code+'|'+res.err_desc+'|'+res.err_msg);
            if(res.err_msg.indexOf('ok')>0){
            	layer.msg('充值成功！');
                window.location.href=returnrul;
            }
        }
    );
}

function callpay(obj)
{
    if (typeof WeixinJSBridge == "undefined"){
        if( document.addEventListener ){
            document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
        }else if (document.attachEvent){
            document.attachEvent('WeixinJSBridgeReady', jsApiCall);
            document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
        }
    }else{
        jsApiCall(obj);
    }
}


function sQrcode(qdata,classname){
	console.log(qdata);
	$("."+classname).empty().qrcode({		// 调用qQcode生成二维码
			render : "canvas",    			// 设置渲染方式，有table和canvas，使用canvas方式渲染性能相对来说比较好
			text : qdata,    				// 扫描了二维码后的内容显示,在这里也可以直接填一个网址或支付链接
			width : "165",              	// 二维码的宽度
			height : "165",             	// 二维码的高度
			background : "#ffffff",     	// 二维码的后景色
			foreground : "#000000",     	// 二维码的前景色
			src: ""    						// 二维码中间的图片
		});

}


/**
 * 扫码支付区域
 * @return {[type]} [description]
 */
function pay_code_area(type) {
	if(type == 0){
		$('.pay_code_area').hide();
	}else if(type == 1){
		$('.pay_code_area').show();
		can_balance(1);
	}
}

var setTime0;
function dao_ji_shi(obj,time=10,txt=''){
  	var obj_t=obj;
  	var time_t= time;

    setTime0=setInterval(function(){
        if(time_t<=1){
            clearInterval(setTime0);
          	obj_t.text(txt);
            return;
        }
        time_t--;
        obj_t.text(txt+'('+time_t+"s)");
    },1000);
}
function can_balance(type) {
	if(type == 0){
		$('.reg_btn').attr('onclick',' ');
		$('.reg_btn').html('请稍后');
      	dao_ji_shi($('.reg_btn'),20,'请稍后');
	}else if(type == 1){
      	clearInterval(setTime0);
		$('.reg_btn').attr('onclick','submit_deposit()');
		$('.reg_btn').html('确认充值');
	}
}

//充值配置
function reg_push(num) {
	if(!num){
		return false;
	}
	$('.bpprice').val(num);
}
